/*
 * FileWindow.java
 *
 * Created on 10. říjen 2008, 14:54
 */

package gui;

import interfaces.Core_Events;

/**
 *
 * @author  Groš
 */
public class FileWindow extends javax.swing.JFrame {

    /** Creates new form FileWindow */
    public FileWindow(Core_Events event) {
        setSystemLook();
        initComponents();
        this.event = event;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Select File");

        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jFileChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jFileChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void buttonClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClicked
    if (evt.getActionCommand().equals(javax.swing.JFileChooser.APPROVE_SELECTION)) 
            event.core_message("FW:Open-File");
    if (evt.getActionCommand().equals(javax.swing.JFileChooser.CANCEL_SELECTION))
            this.dispose();
}//GEN-LAST:event_buttonClicked

    private void setSystemLook() {
        try {
          javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } 
        catch(Exception e) {
          System.out.println("Error setting native look: " + e);
        }
        this.setVisible(true);
    }
    
    public java.io.File getSelectedFile() {
        return jFileChooser1.getSelectedFile();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables
    private Core_Events event;
}
